﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SH3H.CSM.Common.LogUtil
{
    public class LogUtil
    {
        private static ILog _logger = null;

        static LogUtil() 
        {
            log4net.Config.XmlConfigurator.Configure();
        }

        protected static ILog Logger 
        {
            get 
            {
                if (_logger == null) {
                    _logger = log4net.LogManager.GetLogger("Csm.Logger");
                }

                return _logger;
            }
        }
        public static void Debug(string msg)
        {
            Logger.Debug(msg);
        }

        public static void Debug(string format, params object[] ps) 
        {
            Logger.DebugFormat(format, ps);
        }

        public static void Info(string msg)
        {
            Logger.Info(msg);
        }

        public static void Info(string format, params object[] ps) 
        {
            Logger.InfoFormat(format, ps);
        }

        public static void Warn(string msg)
        {
            Logger.Warn(msg);
        }

        public static void Warn(string format, params object[] ps) 
        {
            Logger.WarnFormat(format, ps);
        }

        public static void Error(string msg)
        {
            Logger.Error(msg);
        }

        public static void Error(string msg, Exception ex) 
        {
            Logger.Error(msg, ex);
        }

        public static void Error(string format, params object[] ps) 
        {
            Logger.ErrorFormat(format, ps);
        }
        public static void ThrowException(Exception e)
        {
            Exception ex = e;
            
            while (ex != null)
            {
                Logger.Error("发生异常：" + e.Message + "\r\n" + e.StackTrace);
                ex = ex.InnerException;
                //ThrowException(e.InnerException);
            }
        }
    }
}
